import { defineComponent, onMounted, onUnmounted } from 'vue';
import { IBizContext } from '@ibiz-template/core';
import { toLocalOpenWFRedirectView } from '@ibiz-template/runtime';

export const AppRedirectView = defineComponent({
  setup() {
    const context = IBizContext.create(ibiz.appData?.context || {});

    onUnmounted(() => {
      context.destroy();
    });

    const { href } = window.location;

    async function toRedirect(): Promise<void> {
      await toLocalOpenWFRedirectView(context, href);
    }

    onMounted(() => {
      const el = document.getElementById('app-loading-x') as HTMLDivElement;
      if (el) {
        el.style.display = 'block';
      }
    });

    toRedirect();
  },
  render() {
    return <div>重定向跳转中</div>;
  },
});
